package org.darkforest.listener;

import org.darkforest.common.logger.Logger;
import org.darkforest.common.util.SystemConstant;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Created by valentina on 15/2/12.
 * 启动项目时加载常量到application级内存，web模块中须在web.xml中配置使用
 * 加载内容有：
 * 1、项目路径(暂时只有contextPath并非绝对路径，后续修改 TODO)
 * 2、阿里云图片路径前缀
 */
public class SpringContextInitializedListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent event) {
        String basePath = event.getServletContext().getContextPath();
        Logger.debug(SpringContextInitializedListener.class, "basePath:" + basePath);
        event.getServletContext().setAttribute("basePath", basePath);
        event.getServletContext().setAttribute("alioss_path", SystemConstant.ALIOSS_PATH);
        event.getServletContext().setAttribute("pcweb_goodsDetailPath",SystemConstant.PCWEB_GOODS_DETAIL_PATH);
        event.getServletContext().setAttribute("pcweb_goodscommDetailPath",SystemConstant.PCWEB_GOODSCOMM_DETAIL_PATH);
        event.getServletContext().setAttribute("pcweb_path",SystemConstant.PCWEB_PATH);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
